gen f=1 if firstagem>=9 & firstagem<15
replace f=2 if firstagem>=15 & firstagem<=20
replace f=3 if firstagem>20 & firstagem<=25

foreach k in 500 {

cd "C:\Users\jinzhou\Dropbox\CHINA REACH\weeklydata\monthly_week_match\dynamic_complementarity\boot`k'"
log using "base_boot`k'",replace

tempfile exo_check
tempname table_end
postfile `table_end' str20(denver)   eduy_m eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings  using check_base, replace


local c "(reg eduy_m f if f!=3  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=3  & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A12=e(RW)

local c "(reg eduy_m f if f!=2  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=2  & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A13=e(RW)

local c "(reg eduy_m f if f!=1  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=1 & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A23=e(RW)

	post `table_end' ("p-value1")  (A12[1,1]) (A12[2,1]) (A12[3,1]) (A12[4,1]) (A12[5,1]) (A12[6,1]) (A12[7,1]) (A12[8,1]) 
	post `table_end' ("p-value2")  (A12[1,2]) (A12[2,2]) (A12[3,2]) (A12[4,2]) (A12[5,2]) (A12[6,2]) (A12[7,2]) (A12[8,2])
	post `table_end' ("p-value3")  (A12[1,3]) (A12[2,3]) (A12[3,3]) (A12[4,3]) (A12[5,3]) (A12[6,3]) (A12[7,3]) (A12[8,3])
	
	post `table_end' ("p-value1")  (A13[1,1]) (A13[2,1]) (A13[3,1]) (A13[4,1]) (A13[5,1]) (A13[6,1]) (A13[7,1]) (A13[8,1]) 
	post `table_end' ("p-value2")  (A13[1,2]) (A13[2,2]) (A13[3,2]) (A13[4,2]) (A13[5,2]) (A13[6,2]) (A13[7,2]) (A13[8,2])
	post `table_end' ("p-value3")  (A13[1,3]) (A13[2,3]) (A13[3,3]) (A13[4,3]) (A13[5,3]) (A13[6,3]) (A13[7,3]) (A13[8,3])
	
	post `table_end' ("p-value1")  (A23[1,1]) (A23[2,1]) (A23[3,1]) (A23[4,1]) (A23[5,1]) (A23[6,1]) (A23[7,1]) (A23[8,1]) 
	post `table_end' ("p-value2")  (A23[1,2]) (A23[2,2]) (A23[3,2]) (A23[4,2]) (A23[5,2]) (A23[6,2]) (A23[7,2]) (A23[8,2]) 
	post `table_end' ("p-value3")  (A23[1,3]) (A23[2,3]) (A23[3,3]) (A23[4,3]) (A23[5,3]) (A23[6,3]) (A23[7,3]) (A23[8,3]) 
postclose `table_end'

foreach y of numlist 2/4{
tempfile lang_dul
tempname table_end
postfile `table_end' str20(type) eduy_m eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings using check_base_abi`y', replace

local c "(reg eduy_m f if f!=3 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=3 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A12=e(RW)

local c "(reg eduy_m f if f!=2 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=2 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A13=e(RW)

local c "(reg eduy_m f if f!=1 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_warmth HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=1 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A23=e(RW)

	post `table_end' ("p-value1")  (A12[1,1]) (A12[2,1]) (A12[3,1]) (A12[4,1]) (A12[5,1]) (A12[6,1]) (A12[7,1]) (A12[8,1]) 
	post `table_end' ("p-value2")  (A12[1,2]) (A12[2,2]) (A12[3,2]) (A12[4,2]) (A12[5,2]) (A12[6,2]) (A12[7,2]) (A12[8,2])
	post `table_end' ("p-value3")  (A12[1,3]) (A12[2,3]) (A12[3,3]) (A12[4,3]) (A12[5,3]) (A12[6,3]) (A12[7,3]) (A12[8,3])
	
	post `table_end' ("p-value1")  (A13[1,1]) (A13[2,1]) (A13[3,1]) (A13[4,1]) (A13[5,1]) (A13[6,1]) (A13[7,1]) (A13[8,1]) 
	post `table_end' ("p-value2")  (A13[1,2]) (A13[2,2]) (A13[3,2]) (A13[4,2]) (A13[5,2]) (A13[6,2]) (A13[7,2]) (A13[8,2])
	post `table_end' ("p-value3")  (A13[1,3]) (A13[2,3]) (A13[3,3]) (A13[4,3]) (A13[5,3]) (A13[6,3]) (A13[7,3]) (A13[8,3])
	
	post `table_end' ("p-value1")  (A23[1,1]) (A23[2,1]) (A23[3,1]) (A23[4,1]) (A23[5,1]) (A23[6,1]) (A23[7,1]) (A23[8,1]) 
	post `table_end' ("p-value2")  (A23[1,2]) (A23[2,2]) (A23[3,2]) (A23[4,2]) (A23[5,2]) (A23[6,2]) (A23[7,2]) (A23[8,2]) 
	post `table_end' ("p-value3")  (A23[1,3]) (A23[2,3]) (A23[3,3]) (A23[4,3]) (A23[5,3]) (A23[6,3]) (A23[7,3]) (A23[8,3]) 
	
postclose `table_end'

}	


tempfile exo_check
tempname table_end
postfile `table_end' str20(denver)   eduy_m eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings  using check_base2, replace


local c "(reg eduy_m f if f!=3  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=3  & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A12=e(RW)

local c "(reg eduy_m f if f!=2  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=2  & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A13=e(RW)

local c "(reg eduy_m f if f!=1  & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=1 & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A23=e(RW)

	post `table_end' ("p-value1")  (A12[1,1]) (A12[2,1]) (A12[3,1]) (A12[4,1]) (A12[5,1]) (A12[6,1]) (A12[7,1]) 
	post `table_end' ("p-value2")  (A12[1,2]) (A12[2,2]) (A12[3,2]) (A12[4,2]) (A12[5,2]) (A12[6,2]) (A12[7,2]) 
	post `table_end' ("p-value3")  (A12[1,3]) (A12[2,3]) (A12[3,3]) (A12[4,3]) (A12[5,3]) (A12[6,3]) (A12[7,3]) 
	
	post `table_end' ("p-value1")  (A13[1,1]) (A13[2,1]) (A13[3,1]) (A13[4,1]) (A13[5,1]) (A13[6,1]) (A13[7,1])  
	post `table_end' ("p-value2")  (A13[1,2]) (A13[2,2]) (A13[3,2]) (A13[4,2]) (A13[5,2]) (A13[6,2]) (A13[7,2]) 
	post `table_end' ("p-value3")  (A13[1,3]) (A13[2,3]) (A13[3,3]) (A13[4,3]) (A13[5,3]) (A13[6,3]) (A13[7,3]) 
	
	post `table_end' ("p-value1")  (A23[1,1]) (A23[2,1]) (A23[3,1]) (A23[4,1]) (A23[5,1]) (A23[6,1]) (A23[7,1]) 
	post `table_end' ("p-value2")  (A23[1,2]) (A23[2,2]) (A23[3,2]) (A23[4,2]) (A23[5,2]) (A23[6,2]) (A23[7,2])  
	post `table_end' ("p-value3")  (A23[1,3]) (A23[2,3]) (A23[3,3]) (A23[4,3]) (A23[5,3]) (A23[6,3]) (A23[7,3]) 
postclose `table_end'

foreach y of numlist 2/4{
tempfile lang_dul
tempname table_end
postfile `table_end' str20(type) eduy_m eduy_f eduy_gm  HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings using check_base2_abi`y', replace

local c "(reg eduy_m f if f!=3 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm  HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=3 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A12=e(RW)

local c "(reg eduy_m f if f!=2 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=2 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A13=e(RW)

local c "(reg eduy_m f if f!=1 & abi_lt==`y' & ZB==1 & rankk==1)"
local d "f"
foreach j in eduy_f eduy_gm   HOME_verbal_skills HOME_hostility HOME_learning_literacy HOME_outings{
	local c "`c' (reg `j' f if f!=1 & abi_lt==`y' & ZB==1 & rankk==1)"
	local d "`d',f"
}
rwolf2 `c', indepvars(`d') seed(1234) reps(`k') usevalid
matrix A23=e(RW)

	post `table_end' ("p-value1")  (A12[1,1]) (A12[2,1]) (A12[3,1]) (A12[4,1]) (A12[5,1]) (A12[6,1]) (A12[7,1]) 
	post `table_end' ("p-value2")  (A12[1,2]) (A12[2,2]) (A12[3,2]) (A12[4,2]) (A12[5,2]) (A12[6,2]) (A12[7,2]) 
	post `table_end' ("p-value3")  (A12[1,3]) (A12[2,3]) (A12[3,3]) (A12[4,3]) (A12[5,3]) (A12[6,3]) (A12[7,3]) 
	
	post `table_end' ("p-value1")  (A13[1,1]) (A13[2,1]) (A13[3,1]) (A13[4,1]) (A13[5,1]) (A13[6,1]) (A13[7,1])  
	post `table_end' ("p-value2")  (A13[1,2]) (A13[2,2]) (A13[3,2]) (A13[4,2]) (A13[5,2]) (A13[6,2]) (A13[7,2]) 
	post `table_end' ("p-value3")  (A13[1,3]) (A13[2,3]) (A13[3,3]) (A13[4,3]) (A13[5,3]) (A13[6,3]) (A13[7,3]) 
	
	post `table_end' ("p-value1")  (A23[1,1]) (A23[2,1]) (A23[3,1]) (A23[4,1]) (A23[5,1]) (A23[6,1]) (A23[7,1]) 
	post `table_end' ("p-value2")  (A23[1,2]) (A23[2,2]) (A23[3,2]) (A23[4,2]) (A23[5,2]) (A23[6,2]) (A23[7,2])  
	post `table_end' ("p-value3")  (A23[1,3]) (A23[2,3]) (A23[3,3]) (A23[4,3]) (A23[5,3]) (A23[6,3]) (A23[7,3]) 
	
postclose `table_end'

}	

}

log close